package com.hzhr.iot.log.controller;

import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.log.controller.base.BaseController;
import com.hzhr.iot.log.model.log.LogModel;
import com.hzhr.iot.log.model.log.LogPostModel;
import com.hzhr.iot.log.service.LogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "log", description = "日志")
@RestController
@RequestMapping(value = "")
public class LogController extends BaseController {
    @Autowired
    LogService logService;

    //region post
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 204, message = "无返回实体", response = ResponseExceptionDto.class),
            @ApiResponse(code = 400, message = "请求参数错误", response = ResponseExceptionDto.class),
            @ApiResponse(code = 401, message = "无权限", response = ResponseExceptionDto.class),
            @ApiResponse(code = 403, message = "拒绝执行", response = ResponseExceptionDto.class),
            @ApiResponse(code = 404, message = "无法找到资源", response = ResponseExceptionDto.class),
            @ApiResponse(code = 500, message = "服务端内部错误", response = ResponseExceptionDto.class)
    })
    @ApiOperation(value="新增log资源", notes="新增log资源",produces = "application/json")
    @RequestMapping(value = "/logs", method = RequestMethod.POST)
    @Author
    public ResponseEntity<LogModel> post(@RequestBody LogPostModel body,
                                         @RequestParam @ApiIgnore Map<String, Object> query) {
        LogModel responseBody = logService.post(body);

        if (responseBody == null)return  new ResponseEntity<>(HttpStatus.NO_CONTENT);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion
}
